Skip to content

feat(tags): tag expressions (AND / NOT) and file-level @tags - #1035

Merged
Chemaclass merged 1 commit into
mainfrom
feat/1008-tag-expressions
Aug 9, 2026
Merged

feat(tags): tag expressions (AND / NOT) and file-level @tags#1035
Chemaclass merged 1 commit into
mainfrom
feat/1008-tag-expressions

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1008

Tag selection was weaker than the systems people migrate from: --tag was OR-only with no negation, and tags were per-function only — tagging a whole file meant repeating # @tag above every test.

💡 Changes

  • # @tags a b applies to every test in the file, unioned with per-function # @tag and deduplicated. Collected in the same single awk pass and buffered to END, so a # @tags line placed below the functions still applies to them
  • --tag accepts a&&b (AND) and !a (NOT), combinable as a&&!b. !a matches untagged tests, which meant dropping the early "no tags means no match" short-circuit
  • Repeated --tag flags keep OR semantics between expressions (no behaviour change for existing users), and --exclude-tag still wins
  • Malformed expressions are rejected at parse time with a non-zero exit

The bug worth calling out

--tag 'slow&&' reads as valid and used to silently evaluate as plain slow: consuming the && emptied the remainder, so the while [ -n "$rest" ] loop ended before the empty trailing term was ever checked. Both the evaluator and the validator now always consume one term per iteration and stop only after the last, so the empty term surfaces. The test that first covered this only used '&&', which was caught — a separate case now pins the trailing form.

Verification

Mutation-tested: ignoring negation fails 7 tests, turning AND into OR fails 16, dropping file tags fails 6. Green on the Bash 3.2 floor. Tags containing spaces (# @tag needs db) still select and negate correctly.

Selection is asserted through --list (#1007) rather than by parsing run output.

--tag was OR-only with no negation, and tags were per-function only, so
tagging a whole file meant repeating `# @tag` above every test.

`# @tags a b` now applies to every test in the file, unioned with
per-function `# @tag` and deduplicated. It is collected in the same single
awk pass, buffered to END so a `# @tags` line below the functions still
applies to them.

A single --tag value accepts `a&&b` and `!a`, combinable as `a&&!b`.
Repeated --tag flags arrive comma-joined and keep OR semantics between
expressions, so existing usage is unchanged, and --exclude-tag still wins.
`!a` matches untagged tests, which required dropping the early "no tags
means no match" short-circuit.

A malformed expression is rejected at parse time with a non-zero exit. The
trailing-separator case is the one that mattered: `a&&` reads as valid and
used to evaluate as plain `a`, because consuming the separator emptied the
remainder and ended the loop before the empty term was checked.

Closes #1008
@Chemaclass Chemaclass added the enhancement New feature or request label Aug 9, 2026
@Chemaclass Chemaclass self-assigned this Aug 9, 2026
@Chemaclass
Chemaclass merged commit fe30f88 into main Aug 9, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the feat/1008-tag-expressions branch August 9, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant